<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../../config.inc.php");

session_start();
$_LangPath = "account_bet";
$strTemplatePath = __Admintemplate_Path."/AccountNew/";
include_once(__Language_Path."/selectlanguage_admin.php");
include(__Common_Path."/ShowScore_1.inc.php");
//if(file_exists($_SERVER["DOCUMENT_ROOT"]."/tmp/lock.countResult")){
if($_NumberNormal != "" || $_Message != ""){
	$GLOBALS["errormessage"] = $_strAccount_Bet["onCountResult"];//"結帳中，請稍後！！";
	ErrMsgOutputHTML("Error", "", 1);
}

$arrPower = CheckUsePower("account");
if($arrPower === false)ErrMsgOutputHTML("Error", "", 1);

$isLimit = true;
$isSevenDay = false;
$strBack = $_strAccount_Bet["Bet_Back5"];
$strBackLink = "location.href='Director_index.php?op=Search'";
switch($arrPower[1]){
	case "agent-sub":
		include_once(__Admin_Path."/logincheck_agent_report.php");
		$data["SubID_n"] = $_SESSION["Admin_Info"] -> ParentID;
		$isSevenDay = true;
		$strBack = $_strAccount_Bet["Bet_Back2"];
		$strBackLink = "location.href='Sub_index.php?op=Search'";
		break;

	case "main-sub":
		include_once(__Admin_Path."/logincheck_mainagent_report.php");
		$data["MainID_n"] = $_SESSION["Admin_Info"] -> ParentID;
		$isSevenDay = true;
		$strBack = $_strAccount_Bet["Bet_Back3"];
		$strBackLink = "location.href='index.php?op=Search'";
		break;

	case "stockholder-sub":
		include_once(__Admin_Path."/logincheck_stock_report.php");
		if($_data["WagerType"] != "1"){
			$data["StockID_n"] = $_SESSION["Admin_Info"] -> ParentID;
		}else{
			if($_SESSION["Admin_Info"] -> isAllAccount != 1)$data["DirectorID_n"] = $_SESSION["Admin_Info"] -> DirectorID;
		}
		$strBack = $_strAccount_Bet["Bet_Back4"];
		$strBackLink = "location.href='Stock_index.php?op=Search'";
		break;

	case "director-sub":
		include_once(__Admin_Path."/logincheck_stock_report.php");
		$data["DirectorID_n"] = $_SESSION["Admin_Info"] -> ParentID;
		break;

	case "agent":
		include_once(__Admin_Path."/logincheck_agent_report.php");
		$data["SubID_n"] = $_SESSION["Admin_Info"] -> ID;
		$isSevenDay = true;
		$strBack = $_strAccount_Bet["Bet_Back2"];
		$strBackLink = "location.href='Sub_index.php?op=Search'";
		break;

	case "main":
		include_once(__Admin_Path."/logincheck_mainagent_report.php");
		$data["MainID_n"] = $_SESSION["Admin_Info"] -> ID;
		$isSevenDay = true;
		$strBack = $_strAccount_Bet["Bet_Back3"];
		$strBackLink = "location.href='index.php?op=Search'";
		break;

	case "stockholder":
		include_once(__Admin_Path."/logincheck_stock_report.php");
		//if($_data["WagerType"] != "1"){
			$data["StockID_n"] = $_SESSION["Admin_Info"] -> ID;
		//}
		/*if($_SESSION["Admin_Info"] -> isAllAccount == 1){
			$data["StockID_n"] = $_data["StockID"];
			if($_SESSION["Admin_Info"] -> ParentisAllAccount != 1){
				$data["DirectorID_n"] = $_SESSION["Admin_Info"] -> ParentID;
			}
		}*/
		$strBack = $_strAccount_Bet["Bet_Back4"];
		$strBackLink = "location.href='Stock_index.php?op=Search'";
		break;

	case "director-noitem":
		$data["DirectorID_n"] = $_SESSION["Admin_Info"] -> ID;
	case "director":
		include_once(__Admin_Path."/logincheck_stock_report.php");
		//if($_data["WagerType"] != "1"){
		//	$data["DirectorID_n"] = $_SESSION["Admin_Info"] -> ID;
		//}
		if($_SESSION["Admin_Info"] -> isAllAccount != 1){
			$data["DirectorID_n"] = $_SESSION["Admin_Info"] -> ID;
		}
		break;

	case "all":
		$isLimit = false;
	case "all-limit":
		if($_data["Types"] == "Stock" || $_data["Types"] == "Stocks"){
			$strBack = $_strAccount_Bet["Bet_Back4"];
			$strBackLink = "location.href='Stock_index.php?op=Search'";
		}
		include_once(__Admin_Path."/logincheck_op.php");
		break;

	case "all-old":
		$isLimit = false;
	case "all-old-limit":
		if($_data["Types"] == "Stock"){
			$strBack = $_strAccount_Bet["Bet_Back4"];
			$strBackLink = "location.href='Stock_index.php?op=Search'";
		}
		include_once(__Admin_Path."/logincheck_old.php");
		break;

	default:
		$title = "Error";
		$GLOBALS["errormessage"] =  $_strAccount_Bet["NoPower"]; //""很抱歉！您沒有此程式的使用權限！";
		ErrMsgOutputHTML("Error", "", 1);
		break;
}

include_once(__Modules_Path."/SQLUtility.lib.php");
include_once(__Common_Path."/Lotto.inc.php");
include_once(__Modules_Path."/Lotto.lib.php");
include_once(__Modules_Path."/ChangeTime.lib.php");
include_once(__Modules_Path."/WagerForm.lib.php");
include_once(__Modules_Path."/Account.lib.php");
include_once("Bet_ListResult.php");

$fp = @file($strTemplatePath."Bet_List.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);
	$fp = str_replace("{Bet_Type}", $_data["Bet_Type"], $fp);
	$fp = str_replace("{WagerType}", $_data["WagerType"], $fp);
	$fp = str_replace("{LottoID}", $_data["LottoID"], $fp);
	$fp = str_replace("{GambleID}", $_data["GambleID"], $fp);
	$fp = str_replace("{Types}", $_data["Types"], $fp);
	$fp = str_replace("{PayupDate_0}", $data["PayupDate_x"][0], $fp);
	$fp = str_replace("{PayupDate_1}", $data["PayupDate_x"][1], $fp);
	$fp = str_replace("{GambleID}", $_data["GambleID"], $fp);
	$fp = str_replace("{Number}", $_data["Number"], $fp);
	$fp = str_replace("{SubmitForm}", $strSubmitForm, $fp);
	$fp = str_replace("{Gops}", $_data["ops"], $fp);
	$fp = str_replace("{MemID}", $_data["MemID"], $fp);
	$fp = str_replace("{TotalPage}", $intTotalPage, $fp);
	$fp = str_replace("{PageNow}", $intPageNow, $fp);
	$fp = str_replace("{SubID}", $_data["SubID"], $fp);
	$fp = str_replace("{MainID}", $_data["MainID"], $fp);
	$fp = str_replace("{SelectLotto}", (empty($_data["LottoID"]))?"All":$_arrLotto[$_data["LottoID"]]["Lotto_".$_intLang], $fp);
	$fp = str_replace("{SelectBetType}", (empty($_data["Bet_Type"]))?"All":$_arrBet_Type[$_arrLotto[$_data["LottoID"]]["LType"]][$_data["Bet_Type"]], $fp);

	$fp = str_replace("{BackContent}", $strBack, $fp);
	$fp = str_replace("{BackLink}", $strBackLink, $fp);
	/*if($_data["SubAccount"] == ""){
		$fp = str_replace("{Bet_Agent}", "", $fp);
	}*/

	while(list($k, $v) = each($_strAccount_Bet)){
		$fp = str_replace("{".$k."}", $v, $fp);
	}

	//條列式數字 選擇頁數
	preg_match("/<!--@ LinkPage Start @\/\/-->(.+)<!--@ LinkPage End @\/\/-->/s", $fp, $d);
	for($i = $firstpage; $i <= $lastpage; $i++){
		if($i == $intPageNow){
			$tmpLink = str_replace("{LinkPageLink}", "", $d[1]);
			$tmpLink = str_replace("{LinkPageClass}", "a_text", $tmpLink);
		}else{
			$tmpLink = str_replace("{LinkPageLink}", "href=\"JavaScript:Page(".$i.");\"", $d[1]);
			$tmpLink = str_replace("{LinkPageClass}", "topbar", $tmpLink);
		}
		$tmpLink = str_replace("{LinkPage}", $i, $tmpLink);
		$strLink .= $tmpLink;
	}
	$fp = preg_replace("/<!--@ LinkPage Start @\/\/-->.+<!--@ LinkPage End @\/\/-->/s", $strLink, $fp);

	//下拉式選單 選擇頁數
	preg_match("/<!--@ SelectPage Start @\/\/-->(.+)<!--@ SelectPage End @\/\/-->/s", $fp, $d);
	for($i = 1; $i <= $intTotalPage; $i++){
		$isSelect = ($i == $intPageNow)?" selected":"";
		$tmpSelect = str_replace("{SelectPage}", $i, $d[1]);
		$strSelect .= str_replace("{Selected}", $isSelect, $tmpSelect);
	}
	$fp = preg_replace("/<!--@ SelectPage Start @\/\/-->.+<!--@ SelectPage End @\/\/-->/s", $strSelect, $fp);

	//上一頁
	if($intPageNow < 2){
		$fp = preg_replace("/<!--@ PrePage_2 Start @\/\/-->.+<!--@ PrePage_2 End @\/\/-->/s", "", $fp);
	}else{
		$fp = preg_replace("/<!--@ PrePage_1 Start @\/\/-->.+<!--@ PrePage_1 End @\/\/-->/s", "", $fp);
		$fp = str_replace("{PrePage}", ($intPageNow - 1), $fp);
	}

	//下一頁
	if($intPageNow >= $intTotalPage){
		$fp = preg_replace("/<!--@ NextPage_2 Start @\/\/-->.+<!--@ NextPage_2 End @\/\/-->/s", "", $fp);
	}else{
		$fp = preg_replace("/<!--@ NextPage_1 Start @\/\/-->.+<!--@ NextPage_1 End @\/\/-->/s", "", $fp);
		$fp = str_replace("{NextPage}", ($intPageNow + 1), $fp);
	}


	//下注清單
	preg_match("/<!--@ BetList Start @\/\/-->(.+)<!--@ BetList End @\/\/-->/s", $fp, $d);

	$sumtotals = 0;
	$sumMemStake = 0;
	$sumSubIncome = 0;
	$MainID = "";
	$strSP = "";
	if(is_array($arrRows)){
		if(sizeof($arrRows) > 0){
			$arrOneStake[1] = array(7, 8, 9, 10, 11, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43);
			$arrOneStake[2] = array();
			$arrOneStake[3] = array();
			$arrOneStake[4] = array(15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35);

			while(list($k, $Rows)=each($arrRows)){
				$intLType = $_arrLotto[$Rows -> LottoID]["LType"];
				$strTmp = "";
				$tmpBetList = str_replace("{Show_BetDate}", DateForm($arrConRows[$k] -> BD, $arrConRows[$k] -> BT), $d[1]);
				$tmpBetList = str_replace("{Show_BetTime}", TimeForm($arrConRows[$k] -> BD, $arrConRows[$k] -> BT), $tmpBetList);
				$tmpBetList = str_replace("{Show_BetNo}", $Rows -> ID, $tmpBetList);
				$strSP = ($Rows -> WagerType > 1)?$_strAccount_Bet["SuppleWager".$Rows -> WagerType]."<br />":"";
				$tmpBetList = str_replace("{Show_Account}", $strSP.$arrConRows[$k] -> MemAccount."&nbsp;".(100 - $Rows -> MC*100), $tmpBetList);
				$tmpBetList = str_replace("{Show_BetType}", $_arrLotto[$Rows -> LottoID]["Lotto_".$_intLang]."<br />".$_arrBet_Type[$intLType][$Rows -> Bet_Type], $tmpBetList);
				$strTmpCon =  WagerFormTrans($Rows -> LottoID, $Rows -> Bet_Type, $arrConRows[$k] -> Content);
				$strTmpCon .= "<br /><br />".$arrGameRows[$Rows -> GambleID];
				$tmpBetList = str_replace("{Show_Content}", $strTmpCon, $tmpBetList);
				//if($Rows -> Bet_Type >= 7 && $Rows -> Bet_Type <= 11 && !empty($arrConRows[$k] -> OneStake)){
				if(in_array($Rows -> Bet_Type, $arrOneStake[$intLType]) && !empty($arrConRows[$k] -> OneStake)){
					$WagerNo = round($Rows -> MemStake / $arrConRows[$k] -> OneStake);
					if($WagerNo > 1){
						$strTmp = '<span class="WagerCon_WagerNo_color">'.$arrConRows[$k] -> OneStake.' x '.$WagerNo.'</span><br /><br />';
					}
				}
				$tmpBetList = str_replace("{Show_MemStake}", $strTmp.sprintf("%.1f", $Rows -> MemStake), $tmpBetList);
				if($Rows -> isPayOff < 0){
					$tmpBetList = str_replace("{Show_SubIncome}", "<a style='color: #FF0000'>Cancel</a>", $tmpBetList);
				}else{
					$tmpBetList = str_replace("{Show_SubIncome}", sprintf("%.1f", $Rows -> SubIncome), $tmpBetList);
					$sumtotals ++;
					$sumMemStake += $Rows -> MemStake;
					$sumSubIncome += $Rows -> SubIncome;
				}

				$strBetList .= $tmpBetList;
			}
		}
		@mysql_free_result();
	}
	$fp = preg_replace("/<!--@ BetList Start @\/\/-->.+<!--@ BetList End @\/\/-->/s", $strBetList, $fp);

	$fp = str_replace("{SumTotals}", number_format($sumtotals), $fp);
	$fp = str_replace("{SumMemStake}", sprintf("%.1f",$sumMemStake), $fp);
	$fp = str_replace("{SumSubIncome}", sprintf("%.1f",$sumSubIncome), $fp);

	/*if($_data["Types"] == "Stock"){
		if($_data["SubAccount"] != ""){
			$fp = str_replace("{Show_SubAccount}", $_data["SubAccount"], $fp);
		}else{
			$fp = str_replace("{Show_SubAccount}", $_strAccount_Bet["Sum"], $fp);
		}
		$fp = str_replace("{Sub_Nos}", number_format($Sub_Nos), $fp);
		$fp = str_replace("{Sub_MS}", sprintf("%.1f",$Sub_MS), $fp);
		$fp = str_replace("{Sub_SR}", sprintf("%.1f",$Sub_SR), $fp);
	}else{*/
	$fp = preg_replace("/<!--@ ShowAgent Start @\/\/-->.+<!--@ ShowAgent End @\/\/-->/s", "", $fp);
	//}

//輸出
WebOutputHTML($fp, 1);
?>